<template>
  <div class="posterBoard">
    <livePage :formData="formData"></livePage>
    <formPage
      class="formPage"
      :formData="formData"
      @InitData="BoardInit"
      @getBoardInit="getBoardInit"
      @canleUpdate="canleUpdate"
    ></formPage>
  </div>
</template>
<script>
import livePage from "./components/board/livePage.vue";
import formPage from "./components/board/formPage.vue";
export default {
  name: "posterBoard",
  components: {
    livePage,
    formPage,
  },
  data() {
    return {
      formData: {
        modelType: 1,
        modelOne: {
          codeTextList: [],
          qrCodeGuide: "",
          qrCodeGuide2: "",
          sort: "",
          isUsed: 1,
        },
        modelTwo: {
          codeTextList: [],
          qrCodeGuide: "",
          qrCodeGuide2: "",
          sort: "",
          isUsed: 1,
        },
        modelThree: {
          codeTextList: [],
          qrCodeGuide: "",
          qrCodeGuide2: "",
          sort: "",
          isUsed: 1,
        },
        modelFour: {
          codeTextList: [],
          qrCodeGuide: "",
          qrCodeGuide2: "",
          sort: "",
          isUsed: 1,
        },
      },
      initData: {},
    };
  },
  created() {
    this.getBoardInit();
  },
  methods: {
    //获取模板列表信息
    async getBoardInit() {
      let res = await this.$get(
        "goldenhome/gh/poster/admin_/poster/templet/list"
      );
      if (res && res.returnCode == 1000) {
        console.log(res);
        if (res.dataInfo != null) {
          res.dataInfo.forEach((item) => {
            item.codeTextList = [];
            if (item.qrCodeGuide) {
              item.codeTextList.push("1");
            }
            if (item.qrCodeGuide2) {
              item.codeTextList.push("2");
            }
            if (item.name == "系统模板1") {
              this.formData.modelOne = item;
            } else if ((item.name == "系统模板2")) {
              this.formData.modelTwo = item;
            } else if ((item.name =="系统模板3")) {
              this.formData.modelThree = item;
            } else if ((item.name == "系统模板4")) {
              this.formData.modelFour = item;
            }
          });
          this.initData = JSON.parse(JSON.stringify(this.formData));
        }
      }
    },
    //模块切换时恢复数据
    BoardInit() {
      let obj = JSON.parse(JSON.stringify(this.initData));
      if (this.formData.modelType == 1) {
        this.formData.modelTwo = obj.modelTwo;
        this.formData.modelThree = obj.modelThree;
        this.formData.modelFour = obj.modelFour;
      } else if (this.formData.modelType == 2) {
        this.formData.modelOne = obj.modelOne;
        this.formData.modelThree = obj.modelThree;
        this.formData.modelFour = obj.modelFour;
      } else if (this.formData.modelType == 3) {
        this.formData.modelOne = obj.modelOne;
        this.formData.modelTwo = obj.modelTwo;
        this.formData.modelFour = obj.modelFour;
      } else if (this.formData.modelType == 4) {
        this.formData.modelOne = obj.modelOne;
        this.formData.modelTwo = obj.modelTwo;
        this.formData.modelThree = obj.modelThree;
      }
    },
    //取消编辑
    canleUpdate() {
      let obj = JSON.parse(JSON.stringify(this.initData));
      if (this.formData.modelType == 1) {
        this.formData.modelOne = obj.modelOne;
      } else if (this.formData.modelType == 2) {
        this.formData.modelTwo = obj.modelTwo;
      } else if (this.formData.modelType == 3) {
        this.formData.modelThree = obj.modelThree;
      } else if (this.formData.modelType == 4) {
        this.formData.modelFour = obj.modelFour;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.posterBoard {
  padding: 30px;
  display: flex;
  .formPage {
    flex-grow: 1;
  }
}
</style>